package com.is.add.controller.web;

import com.is.add.controller.vo.DataCountInVO;
import com.is.add.enmus.DepositOptTypeEnum;
import com.is.add.service.DepositService;
import com.is.add.service.OrderService;
import com.is.add.service.SettleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**
 * 导出报表
 * Created by jackie on 2016/08/01.
 */
@Controller
@RequestMapping("export")
@CrossOrigin
public class ExportController {
    @Autowired
    private OrderService orderService;
    @Autowired
    private DepositService depositService;
    @Autowired
    private SettleService settleService;
    /**
     * 统计明细导出
     */
    @RequestMapping(value = "/excel/dataCountDetails",method = RequestMethod.POST)
    @ResponseBody
    public void exportDataCountDetails(
            DataCountInVO dataCountInVO,
            HttpServletRequest request,
            HttpServletResponse response) {
        Map<String,String> map =new HashMap<>();
        if (dataCountInVO.getShop() != null && !"".equals(dataCountInVO.getShop())){
            map.put("shop", dataCountInVO.getShop() );
        }
        if (dataCountInVO.getSales() != null && !"".equals(dataCountInVO.getSales())){
            map.put("sales",dataCountInVO.getSales());
        }
        if (dataCountInVO.getPayType()  != null){
            map.put("payType",dataCountInVO.getPayType().name());
        }
        if (dataCountInVO.getOrderType() != null){
            map.put("orderType",dataCountInVO.getOrderType().name());
        }
        if (dataCountInVO.getCity() != null){
            map.put("city",dataCountInVO.getCity());
        }
        if (dataCountInVO.getSportsType() != null){
            map.put("sportsType",dataCountInVO.getSportsType());
        }
        if (dataCountInVO.getGroups() != null){
            map.put("groups",dataCountInVO.getGroups());
        }
        if (dataCountInVO.getSearchKey() != null && !"".equals(dataCountInVO.getSearchKey())){
            map.put("searchKey",dataCountInVO.getSearchKey());
        }
        map.put("orderStatus",dataCountInVO.getOrderStatus().name());
        map.put("timeType",dataCountInVO.getTimeType().name());
        map.put("startTime",dataCountInVO.getStartTime() + " 00:00:00");
        map.put("endTime",dataCountInVO.getEndTime() + " 23:59:59");
        this.orderService.exportDataCountDetails(request,response,map);
    }

    /**
     * 一键导出 财务-业务综合表
     */
    @RequestMapping(value = "/excel/GeneralExcel")
    public void exportGeneralExcel(HttpServletResponse response,
                            @RequestParam String startTime,
                            @RequestParam String endTime)throws ServletException {
        startTime = startTime+" 00:00:00";
        endTime = endTime + " 23:59:59";
        this.orderService.exportGeneralExcel(response,startTime,endTime);
    }

    /**
     * 导出备用金余额
     */
    @RequestMapping(value = "/excel/depositBalance")
    public void exportDepositBalance(HttpServletResponse response,
                                     @RequestParam String endTime,
                                     @RequestParam(required = false) Long depositType)throws ServletException {
        this.depositService.exportDepositBalance(response,endTime,depositType);
    }

    /**
     * 导出备用金流水
     */
    @RequestMapping(value = "/excel/depositRechargeRecord")
    public void exportDepositRechargeRecord(HttpServletResponse response,
                                            @RequestParam String startTime,
                                            @RequestParam String endTime,
                                            @RequestParam(required = false) DepositOptTypeEnum optType)throws ServletException {
        this.depositService.exportDepositRechargeRecord(response,startTime,endTime,optType);
    }

    /**
     * 导出周结算数据
     */
    @RequestMapping(value = "/excel/settleDoc")
    public void exportSettleDoc(HttpServletResponse response,
                                     @RequestParam String startTime,
                                     @RequestParam String endTime)throws ServletException {
        this.settleService.exportSettleDoc(response,startTime,endTime);
    }

}
